package com.runa.monitor.platinterface.platService;


import com.runa.monitor.platinterface.netservice.equipment.Concentrator;
import com.runa.monitor.platinterface.netservice.equipment.LangKaBoDriver;
import com.runa.monitor.platinterface.netservice.equipment.NetEqu;
import com.runa.monitor.platinterface.netservice.equipment.PublicBuildDriver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class AfterOnlineService {

    @Resource
    private NetEquService netEquService;

    public void trigger(String netSerial) {
        NetEqu<String> netEqu = netEquService.getNetEquBySerialCache(netSerial);
        if (netEqu instanceof Concentrator) {
            concentratorTiming(netEqu);
            ((Concentrator) netEqu).readTerminalVersion();
            ((Concentrator) netEqu).readSimCardIccid();
        } else if (netEqu instanceof LangKaBoDriver) {
            ((LangKaBoDriver) netEqu).readElectricityMeter();
        } else if (netEqu instanceof PublicBuildDriver) {
            ((PublicBuildDriver) netEqu).readElectricityMeter();
        }
    }

    public void concentratorTiming(NetEqu<String> netEqu) {
        if (null != netEqu.commNetEquipment) {
            if (null != netEqu.commNetEquipment.getModel() && netEqu.commNetEquipment.getModel().startsWith("RC-ZNCL")) {
                ((Concentrator) netEqu).timing();
            }
        }
    }
}
